package day35_1456;

import java.util.*;

/**
 * @ClassName Solution
 * @Description 超时
 * @Author clockTown
 * @Date 2021/6/13 20:13
 * @Version 1.0
 */
public class Solution {

    public int maxVowels(String s, int k) {
        HashSet<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');

        int maxCount = 0;
        int temp = 0;
        int j = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i <= k - 1){
                if (set.contains(s.charAt(i))) {
                    maxCount++;
                }
            }else {
                if (i == k){
                    temp = maxCount;
                }
                int count = temp;
                if (set.contains(s.charAt(j))){
                    count--;
                }
                if (set.contains(s.charAt(i))){
                    count++;
                }
                j++;
                temp = count;
                maxCount = Math.max(maxCount, count);
            }
        }
        return maxCount;
    }

    public static void main(String[] args) {
//        String s = "abciiidef";
//        int k = 3;
//        String s = "aeiou";
//        int k = 2;
//        String s = "leetcode";
//        int k = 3;

//        Solution sol = new Solution();
//        System.out.println(sol.maxVowels(s, k));
    }
}
